package alijk.dataView.services;

import java.net.URLEncoder;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
/**
 * Cache-Control	private
	Content-Encoding	gzip
	Content-Length	5054
	Content-Type	text/html; charset=gb2312
	Date	Wed, 10 Dec 2014 06:28:19 GMT
	Server	Microsoft-IIS/7.5
	Vary	Accept-Encoding
	X-AspNet-Version	2.0.50727
	X-Powered-By	ASP.NET
 * @time 2014年12月10日 下午2:59:31
 * @author CheWenliang
 */
public class DrugInfoClient {
	public static void main(String[] args) throws Exception {
		String body = "";  
		/*
		 * __VIEWSTATE和__EVENTVALIDATION每次都会变,但知道一个值时可以复用,甚好
		 */
		String url = "http://search.anccnet.com/searchResult2.aspx?"
				+ "__VIEWSTATE=%2FwEPDwULLTEzODQxNzY5NjNkZEc4gDy0wp5ERjILg2b7lTTH3F%2Bw"
				+ "&__EVENTVALIDATION=%2FwEWAwKK7u6vCQLd5eLQCQLmjL2EBxmZU7jWYoh9371phOcBPCjfgdVD"
				+ "&gdsBtn=%C9%CC%C6%B7%CB%D1%CB%F7&keyword=";
		String keyWord = "醋氯芬酸片";
		//因为这个网站是用gb2312做为编码,所以要对keyword进行2312的转码
		keyWord = URLEncoder.encode(keyWord,"gb2312");
		HttpClient httpClient = new HttpClient();  
		
		//这个网站以post方式取数据有问题,不知道为什么,所以用GET
		GetMethod method = new GetMethod(url+keyWord);
		httpClient.executeMethod(method);
		 
		body = method.getResponseBodyAsString();
		 
		System.out.println(body);
		// 释放链接
		method.releaseConnection();
		httpClient.getHttpConnectionManager().closeIdleConnections(0);
	}
}
